<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div class="top-title">检验组</div>
          <rm-ddl-common datatype="labgroup" dataname="检验组" @change="btnQuery" v-model="selLabgroupid" width="130px" key="1"></rm-ddl-common>
          <div class="top-button">
              <el-button @click="btnQuery" icon="el-icon-search" type="primary" v-has="'PINQUERY'" :disabled="bChangeFlag">查询</el-button>
              <el-button @click="btnAdd" icon="el-icon-plus" v-has="'PADD'" :disabled="bChangeFlag">新增</el-button>
              <el-button @click="btnDel" icon="el-icon-delete" v-has="'PDELETE'" :disabled="bChangeFlag">删除</el-button>
              <el-button @click="btnSave" icon="el-icon-document" v-has="'PMODIFY'" :disabled="!bChangeFlag">保存</el-button>
              <el-button @click="btnClear" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="500" :maxfixsize="500" :minfixsize="500">
              <div style="height:100%">
                  <vxe-table :data.sync="leftData" :loading="bLeftLoading" :keyboard-local-config="keyLocalConfig" :row-class-name="lRowClassName" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" @current-change="CurrentChangeEvent" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="lXTable" resizable size="mini" stripe show-header-overflow="tooltip" show-overflow="tooltip">
                      <vxe-table-column field="labgroupname" title="检验组" width="100" header-align="center" align="left"></vxe-table-column>
                      <vxe-table-column field="batchno" title="批号" width="120" header-align="center" align="left"></vxe-table-column>
                      <vxe-table-column field="qcname" title="质控品名称" width="120" header-align="center" align="left"></vxe-table-column>
                      <vxe-table-column field="createdate" title="发放日期" width="90" align="center" :formatter="['toDateString', 'yyyy/MM/dd']"></vxe-table-column>
                      <vxe-table-column field="expriedt" title="有效期" width="90" align="center" :formatter="['toDateString', 'yyyy/MM/dd']"></vxe-table-column>
                      <vxe-table-column field="vendorname" title="生产厂商" width="80" header-align="center" align="left">
                      </vxe-table-column>
                      <vxe-table-column field="manudt" title="生产日期" width="90" align="center" :formatter="['toDateString', 'yyyy/MM/dd']"></vxe-table-column>
                      <vxe-table-column field="labgroupid" title="检验组ID" width="80" header-align="center" align="center"></vxe-table-column>
                  </vxe-table>
              </div>
              <template v-slot:fix>
                  <div v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="height:100%">
                      <rm-layout-top splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="130" :canDrag="false">
                          <template v-slot:fix>
                              <div style="height:130px;border:1px solid #CCC">
                                  <el-form :label-position="labelPosition" label-width="80px" :model="detailData" :disabled="bEmpty">
                                      <table class="table1style" style="width:100%;font-size:12px">
                                          <tr>
                                              <td align="right" style="color:#F56C6C">检验组</td>
                                              <td>
                                                  <rm-ddl-common :appendtobody="true" @change="LabgroupidChange" datatype="labgroup" dataname="检验工作组" v-model="detailData.labgroupid" width="170px" ref="input0" @keyup.enter.native="NextFocus(0)" :clearable="false"></rm-ddl-common>
                                              </td>
                                              <td align="right" style="color:#F56C6C">批号</td>
                                              <td>
                                                  <el-input v-model="detailData.batchno" @input="HasChange" ref="input1" @keyup.enter.native="NextFocus(1)" style="width:170px"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="color:#F56C6C">质控品名称</td>
                                              <td>
                                                  <el-input v-model="detailData.qcname" @input="HasChange" ref="input2" @keyup.enter.native="NextFocus(2)" style="width:170px"></el-input>
                                              </td>
                                              <td align="right" style="color:#F56C6C">发放日期</td>
                                              <td>
                                                  <el-date-picker v-model="detailData.createdate" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" @input="HasChange" ref="input3" @keyup.enter.native="NextFocus(3)" style="width:170px"></el-date-picker>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">生产厂商</td>
                                              <td>
                                                  <rm-ddl-common :appendtobody="true" datatype="invvendor" dataname="厂商" v-model="detailData.manufacturer" @change="manufacturerChange" ref="input4" @keyup.enter.native="NextFocus(4)" width="170px"></rm-ddl-common>
                                              </td>
                                              <td align="right">生产日期</td>
                                              <td>
                                                  <el-date-picker v-model="detailData.manudt" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" @input="HasChange" ref="input5" @keyup.enter.native="NextFocus(5)" style="width:170px"></el-date-picker>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">
                                                  有效期
                                              </td>
                                              <td>
                                                  <el-date-picker v-model="detailData.expriedt" type="date" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" @input="HasChange" ref="input6" @keyup.enter.native="NextFocus(6)" style="width:170px"></el-date-picker>
                                              </td>
                                          </tr>
                                      </table>
                                  </el-form>
                              </div>
                          </template>
                          <div style="height:100% ;width:100%;background-color:#ddccbb;" class="detailxTable">
                              <vxe-table :data="rXTableData" :loading="bLeftLoading" :keyboard-config="selKeyConfig" :keyboard-local-config="selKeyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: false,showIcon:false,autoClear:true}" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="rXTable" resizable size="mini" stripe :row-class-name="rRowClassName" :cell-class-name="rCellClassName" :edit-closed="rEditClosed" :mouse-config="{selected: true}" show-header-overflow="tooltip" show-overflow="tooltip">
                                  <vxe-table-column field="rpt_item" title="项目代码(双击弹窗)" width="200" :edit-render="{name: 'input',autoselect: true,}">
                                      <template v-slot:header="{column}">
                                          <span style="color:#F56C6C;">项目代码(双击弹窗)</span>
                                      </template>
                                      <template v-slot:edit="{row}">
                                          <el-input v-model="row.rpt_item" style="width:100%" placeholder="" @keyup.space.native="popGetRow(row);" @dblclick.native="popGetRow(row)" readonly>
                                          </el-input>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="qcresult" title="结果" width="60" header-align="center" align="right" :edit-render="{name: 'input',autoselect: true,events: {change: qcresultChange},}">
                                  </vxe-table-column>
                                  <vxe-table-column field="targetresult" title="靶值" width="60" header-align="center" align="right" :edit-render="{name: 'input',autoselect: true,events: {change: targetresultChange},}">
                                  </vxe-table-column>
                                  <vxe-table-column field="bias" title="偏倚" width="60" header-align="center" align="right">
                                  </vxe-table-column>
                                  <vxe-table-column field="resultdt" title="结果时间" width="90" :formatter="['toDateString', 'yyyy/MM/dd']" align="center" sortable>
                                  </vxe-table-column>
                                  <vxe-table-column field="username" title="录入人" width="60" align="center"></vxe-table-column>

                                  <vxe-table-column field="qcresulttxt" title="结果文本" width="120">
                                  </vxe-table-column>
                                  <vxe-table-column field="targetresulttxt" title="文本靶值" width="120">
                                  </vxe-table-column>
                                  <template v-slot:fix>
                                      <div style="font-size:17px;padding:3px;background-color:#fff;text-align:center;font-weight:bold">
                                          <el-button @click="btnDetailAdd()" class="el-button--310" :disabled="bEmpty">新增明细</el-button>
                                          <el-button @click="btnDetailDel()" class="el-button--310" :disabled="bEmpty">删除明细</el-button>
                                      </div>
                                  </template>
                              </vxe-table>
                          </div>
                      </rm-layout-top>
                  </div>
              </template>
          </rm-layout-right>
          <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="质控项目选择" :visible.sync="bPopRptItem" v-if="bPopRptItem" :keyboard-local-config="keyLocalConfig">
              <rm-pop-selinstrptitem :labgroupid="this.detailData.labgroupid" :multiple_choice="true" @cancel="bPopRptItem=false" @change="addrptitem"></rm-pop-selinstrptitem>
          </el-dialog>
      </div>
  </div>
</template>

<script type="text/javascript">
import XE from "xe-utils";
export default {
  name: "LIS525",
  data() {
      return {
          txtsearch: "",
          selLabgroupid: "",
          actionindex: "M",
          labelPosition: "right",
          deflabgroupid: 0,
          bEmpty: false,
          bLeftLoading: false,
          bChangeFlag: false,
          bPopRptItem: false,
          bPageInitLoading: false,
          selKeyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          selKeyLocalConfig: {
              isArrow: true,
          },
          keyLocalConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          detailData: {
              labgroupid: 0,
              labgroupname: "",
              batchno: "",
              qcname: "",
              createdate: "",
              manufacturer: "",
              manudt: "",
              expriedt: "",
          },
          selectConfig: { tigger: "row" },
          labMedRow: {},
          tempmed: {},
          tmpdetailData: {},
          selrow: [],
          AddData: [], //新增数据 用于变色
          ModData: [], //修改数据 用于变色
          lXTableData: [],
          rXTableData: [],
          leftData: [],
          invvendorOption: [], //生产厂商
      };
  },
  created() {
      this.initOption();
  },
  watch: {},
  computed: {
      //排序
      autoSeq() {
          let len = this.$refs.rXTable.tableData.length;
          return (len + 1) * 10;
      },
  },
  methods: {
      //初始化组件getOption
      async initOption() {
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS525",
                  method: "post",
                  data: {
                      action: "init_option",
                  },
              })
              .then((res) => {
                  if (res.flag != -1) {
                      this.deflabgroupid = res.deflabgroupid;
                  }
              })
              .catch((e) => {
                  console.log("e", e);
                  this.bLeftLoading = false;
              });
          this.btnQuery();
      },
      //----------------- 查询类 ----------------- //
      //主表查询
      filterQuery() {
          let filterName = this.txtsearch.trim();
          if (filterName) {
              let rest = this.lXTableData.filter((item) => {
                  return item.labgroupid.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.createdate ? item.createdate.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.qcname ? item.qcname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
              });
              this.leftData = rest;
          } else {
              this.leftData = this.lXTableData;
          }
          let row = this.leftData[0];
          if (row) {
              this.HightLightRow(row);
          } else {
              this.HightLightRow(false);
          }
      },
      btnQuery() {
          this.AddData = [];
          this.ModData = [];
          this.bLeftLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS525",
                  method: "post",
                  data: {
                      action: "qc_cclqcs_query",
                      labgroupid: this.selLabgroupid,
                  },
              })
              .then((res) => {
                  this.lXTableData = res;
                  if (res.length > 0) {
                      this.lXTableData = res;
                      this.bEmpty = false;
                  } else {
                      this.lXTableData = [];
                      this.bEmpty = true;
                  }
                  this.filterQuery();
                  if (this.lXTableData.length == 0) this.actionindex = "A";
                  // this.leftData=XE.clone(this.lXTableData,true)
                  // this.HightLightRow(this.leftData[0]);
                  this.bLeftLoading = false;
              })
              .catch((e) => {
                  console.log("e", e);
                  this.bLeftLoading = false;
              });
      },
      //明细查询 -- 主表，子表
      async detailQuery(row) {
          try {
              this.selrow = row;
              this.actionindex = "M";
              this.bPageInitLoading = true;
              this.detailData = {};
              this.rXTableData = [];
              const res = await this.$tool.request({
                  url: "LIS/LIS5/LIS525",
                  method: "post",
                  data: {
                      action: "qc_cclqcs_query_detail",
                      labgroupid: row.labgroupid,
                      batchno: row.batchno,
                  },
              });
              if (res) {
                  if (res.qccclqcs.length > 0) {
                      this.detailData = res.qccclqcs[0];
                      this.rXTableData = res.qccclqcdata;
                      this.rXTableData.forEach((e) => {
                          if (e.qcresult != null && e.qcresult != "" && e.targetresult != null && e.targetresult != "") {
                              var result = XE.toNumber(e.qcresult);
                              var target = XE.toNumber(e.targetresult);
                              if (result > 0 && target > 0) {
                                  e.bias = XE.toNumber(XE.toFixedString((100 * Math.abs(result - target)) / target, 2));
                              } else {
                                  e.bias = "";
                              }
                          }
                      });
                  } else {
                      this.detailData = {};
                      this.rXTableData = [];
                  }
                  this.tmpdetailData = XE.clone(this.detailData, true);
                  this.bPageInitLoading = false;
              }
          } catch (e) {
              console.log("e", e);
              this.bPageInitLoading = false;
          }
      },
      //主键查询  是否重复
      ChkKeyId() {
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS525",
                  method: "post",
                  data: {
                      action: "qc_cclqcs_chkkeyid",
                      labgroupid: this.detailData.labgroupid,
                  },
              })
              .then((res) => {
                  if (res == "1") {
                      this.$alert("项目代码重复，请重新填写！");
                      this.$refs.input0.focus();
                  }
              })
              .catch((e) => {
                  console.log("e", e);
              });
      },
      //----------------- 按钮类 -----------------//
      //新增
      btnAdd() {
          this.bEmpty = false;
          this.bChangeFlag = true;
          this.actionindex = "A";
          var sellabgroupid = XE.toNumber(this.selLabgroupid);
          var deflabgroupid = XE.toNumber(this.deflabgroupid);
          this.detailData = {
              labgroupid: sellabgroupid > 0 ? sellabgroupid : deflabgroupid > 0 ? deflabgroupid : 0,
              labgroupname: "",
              batchno: "",
              qcname: "",
              createdate: XE.toDateString(new Date(), "yyyy-MM-dd"),
              manufacturer: "",
              manudt: "",
              expriedt: "",
          };
          if (sellabgroupid && sellabgroupid > 0) {
              this.detailData;
          }
          this.rXTableData = [];
          this.$refs.input1.focus();
      },
      btnDetailAdd() {
          this.$refs.rXTable.insertAt(
              {
                  rpt_item: "",
                  rpt_itemname: "",
                  rpt_itemcode: "",
                  qcresult: "",
                  qcresulttxt: "",
                  resultdt: "",
                  labgroupid: this.detailData.labgroupid,
                  batchno: this.detailData.batchno,
                  username: this.$tool.getSession(this.$tool.loginusername),
                  userno: this.$tool.getSession(this.$tool.loginusern0),
                  targetresult: "",
                  targetresulttxt: "",
              },
              -1
          );
          this.$refs.rXTable.scrollToRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1]);
          this.$refs.rXTable.setCurrentRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1]);
          this.$refs.rXTable.setActiveRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1], "rpt_item");
          this.bChangeFlag = true;
      },
      btnDetailDel() {
          // this.$refs.rXTable.remove(this.$refs.rXTable.getCurrentRow()),
          //                 this.bChangeFlag = true
          try {
              var delrow = this.$refs.rXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.rXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.rXTable.remove(delrow);
                  let havedata = this.$refs.rXTable.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.rXTable.setCurrentRow(selectrow);
                  } else {
                      this.$refs.rXTable.setCurrentRow(null);
                  }
                  this.bChangeFlag = true; 
              }
          } catch (e) {
              console.log("error", e);
          }
      },
      //删除 -- 弹窗提示
      btnDel() {
          var delrow = this.$refs.lXTable.getCurrentRow();
          this.$confirm('确定删除项目名称为<b style="color:red">' + delrow.qcname + "</b>的记录吗？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              dangerouslyUseHTMLString: true,
              type: "warning",
          })
              .then(() => {
                  this.actionindex = "D";
                  this.confirmDel();
              })
              .catch((e) => {
                  this.$message({
                      type: "info",
                      message: "已取消删除",
                  });
              });
      },
      //删除 -- 确认删除
      async confirmDel() {
          try {
              var delrow = this.$refs.lXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.lXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  await this.btnSave().then(() => {
                      this.$refs.lXTable.remove(delrow);
                      this.lXTableData.splice(rowindex, 1);
                      let havedata = this.$refs.lXTable.tableData;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.HightLightRow(selectrow);
                      } else {
                          this.HightLightRow(false);
                      }
                  });
              }
          } catch (e) {
              this.ErrorCatch(e, "", "error");
          }
      },
      //取消 -- 取消操作，数据还原
      btnClear() {
          this.$confirm("您确定要取消这次改动吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  this.bChangeFlag = false;
                  if (this.$refs.lXTable.tableData.length == 0) {
                      this.bEmpty = false;
                  }
                  this.detailQuery(this.selrow);
              })
              .catch((e) => {});
      },
      //保存 -- 保存新增，修改，删除主表: lab_medgroup 子表: lab_medgroupdetail 操作//
      async btnSave() {
          try {
              if (!this.detailData.labgroupid) {
                  this.$alert("请选择检验组。");
                  this.$refs.input0.focus();
                  return false;
              }
              if (!this.detailData.batchno) {
                  this.$alert("请填写批号。");
                  this.$refs.input2.focus();
                  return false;
              }
              if (!this.detailData.qcname) {
                  this.$alert("请填写质控品名称。");
                  this.$refs.input2.focus();
                  return false;
              }
              let data = this.$refs.rXTable.getTableData().fullData;
              data.sort((a, b) => {
                  return a.batchno - b.batchno;
              });
              for (let i = 0, len = data.length; i < len; i++) {
                  data[i].labgroupid = this.detailData.labgroupid; //修正保存。
                  data[i].batchno = this.detailData.batchno; //修正保存。
              }
              const res = await this.$tool.request({
                  url: "LIS/LIS5/LIS525",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "qc_cclqcs_query_save",
                      utype: this.actionindex,
                      oldinfo: this.tmpdetailData,
                      newinfo: this.detailData,
                      qccclqcdata: this.$refs.rXTable.getRecordset(),
                  },
              });
              if (res.errcode == "1") {
                  this.$message.success("保存成功！");
                  this.bChangeFlag = false;
                  if (this.actionindex == "A") {
                      if (this.AddData.indexOf(this.detailData.labgroupid) == -1) this.AddData.push(this.detailData.labgroupid);

                      this.$refs.lXTable.insert(this.detailData).then(({ row }) => {
                          this.HightLightRow(row);
                          this.lXTableData.push(row);
                      });
                  } else if (this.actionindex == "M") {
                      if (this.ModData.indexOf(this.detailData.labgroupid) == -1) this.ModData.push(this.detailData.labgroupid);
                      await this.SetToTable(this.detailData).then((row) => {
                          this.HightLightRow(row);
                      });
                  } else {
                      this.actionindex = "M";
                  }
              } else {
                  this.ErrorCatch(res.errmsg, "保存失败:", "error");
              }
          } catch (e) {
              console.log("e", e);
          }
      },
      ErrorCatch(e, msg, type) {
          this.$alert(msg + e, "提示", {
              confirmButtonText: "确定",
              type: type ? type : "error",
          });
      },
      //--------------- 数据改变及其他功能 ---------------//
      //行改变事件
      async CurrentChangeEvent({ row }) {
          if (this.bChangeFlag) {
              this.$refs.lXTable.setCurrentRow(this.selrow);
              return false;
          } else {
              await this.detailQuery(row);
          }
      },
      qcresultChange({ row }, inputValue) {
          this.HasChange();
          let qcresult = inputValue.target.value;
          if (qcresult != "" && row.targetresult != "" && qcresult != null && row.targetresult != null) {
              var result = XE.toNumber(qcresult);
              var target = XE.toNumber(row.targetresult);
              if (result > 0 && target > 0) {
                  console.log("GO");
                  row.bias = XE.toNumber(XE.toFixedString((100 * Math.abs(result - target)) / target, 2));
              } else {
                  row.bias = "";
              }
          }
      },
      targetresultChange({ row }, inputValue) {
          this.HasChange();
          let targetresult = inputValue.target.value;
          if (row.qcresult != "" && targetresult != "" && row.qcresult != null && targetresult != null) {
              var result = XE.toNumber(row.qcresult);
              var target = XE.toNumber(targetresult);
              if (result > 0 && target > 0) {
                  console.log("GO");
                  row.bias = XE.toNumber(XE.toFixedString((100 * Math.abs(result - target)) / target, 2));
              } else {
                  row.bias = "";
              }
          }
      },
      manufacturerChange(c, v) {
          this.HasChange();
      },
      LabgroupidChange() {
          var datalen = this.$refs.rXTable.tableData.length;
          if (datalen > 0) {
              this.$confirm("修改检验组会清空当前质控项目,确认切换工作组?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              }).then(() => {
                  this.HasChange();
                  for (var i = 0; i < datalen; i++) {
                      this.$refs.rXTable.setCurrentRow(this.$refs.rXTable.tableData[0]);
                      var delrow = this.$refs.rXTable.getCurrentRow();
                      console.log("🐘🐘🐘🐘🐘 —— delrow", delrow);
                      if (delrow) {
                          var alld = this.$refs.rXTable.tableData;
                          var rowindex = alld.indexOf(delrow);
                          this.$refs.rXTable.remove(delrow);
                      }
                  }
                  this.$message({
                      showClose: true,
                      message: "切换成功，在保存数据前，您可通过取消按钮恢复原数据。",
                      type: "success",
                  });
              });
          } else {
              this.HasChange();
          }
      },
      addrptitem(rptitemList) {
          this.bPopRptItem = false;
          var ishave = false;
          var datarecord = this.$refs.rXTable.tableData;
          let initdata = [];
          for (var i = 0; i < rptitemList.length; i++) {
              if (datarecord.length > 0) {
                  try {
                      datarecord.forEach((item) => {
                          if (item.rpt_itemcode == rptitemList[i].rpt_itemcode) {
                              ishave = true;
                              throw Error();
                          } else {
                              ishave = false;
                          }
                      });
                  } catch (e) {}
              }
              if (ishave) {
                  continue;
              }
              let addrecord = {
                  rpt_item: rptitemList[i].rpt_itemname + "[" + rptitemList[i].rpt_itemcode + "]",
                  rpt_itemname: rptitemList[i].rpt_itemname,
                  rpt_itemcode: rptitemList[i].rpt_itemcode,
                  qcresult: "",
                  qcresulttxt: "",
                  resultdt: "",
                  username: this.$tool.getSession(this.$tool.loginusername),
                  userno: this.$tool.getSession(this.$tool.loginusern0),
                  targetresult: "",
                  targetresulttxt: "",
              };
              initdata.push(addrecord);
          }
          var currow = this.$refs.rXTable.getCurrentRow();
          //判断当前行是否是新增的空行
          if (currow && (currow.rpt_item == "" || currow.rpt_item == null)) {
              var alld = this.$refs.rXTable.tableData;
              var rowindex = alld.indexOf(currow);
              rowindex = this.$refs.rXTable.tableData.indexOf(currow);
              this.$refs.rXTable.remove(currow);
          }
          this.$refs.rXTable.insert(initdata);
          if (initdata > 0) {
              this.HasChange();
              this.$refs.rXTable.setActiveCell(this.addrecord, "batchno");
          }
          this.bPopRptItem = false;
      },
      //保存后不刷新左侧主表,前台赋值。
      SetToTable(obj) {
          return new Promise((s, f) => {
              this.selrow.labgroupid = obj.labgroupid;
              this.selrow.batchno = obj.batchno;
              this.selrow.qcname = obj.qcname;
              this.selrow.createdate = obj.createdate;
              this.selrow.manufacturer = obj.manufacturer;
              this.selrow.vendorname = obj.manufacturer;
              this.selrow.manudt = obj.manudt;
              this.selrow.expriedt = obj.expriedt;
              s(this.selrow);
              return;
          });
      },
      // 焦点跳转
      NextFocus(index) {
          var focusIndex = index + 1;
          var that = this;
          if (index < 6) {
              setTimeout(function () {
                  if ([3, 5, 6].includes(index)) {
                      that.$refs["input" + index].blur();
                  }
                  if (index != 4) {
                      that.$refs["input" + focusIndex].focus();
                  } else {
                      that.$refs["input" + focusIndex].$refs.ddlmainSelect.focus();
                  }
              }, 5);
          } else {
              //表单最后一格 回车 跳转明细表
              this.btnDetailAdd();
              this.bChangeFlag = true;
          }
      },
      //数据发生改变 -- 按钮禁用/可用切换
      HasChange() {
          this.bChangeFlag = true;
      },
      //获取 弹窗 行数据
      popGetRow(row) {
          this.tempmed = XE.clone(row.rpt_itemcode);
          this.RptItemRow = row;
          this.bPopRptItem = true;
      },
      //获取pop 组件 hidecode，hidename
      RptItemRowChange(c, v) {
          this.RptItemRow.rpt_itemcode = c;
          this.RptItemRow.rpt_item = v + "[" + c + "]";
          if (this.tempmed != this.RptItemRow.rpt_itemcode) {
              this.HasChange();
          }
          this.bPopRptItem = false;
          this.$refs.rXTable.setActiveCell(this.RptItemRow, "batchno");
      },
      //设置高亮选中行
      async HightLightRow(row) {
          if (!!row) {
              this.$refs.lXTable.setCurrentRow(row);
              await this.detailQuery(row);
          } else {
              this.$refs.lXTable.setCurrentRow(null);
              this.detailData = {};
              this.tmpdetailData = {};
              this.rXTableData = [];
          }
      },
      rEditClosed({ row, column }) {
          if (column.property == "loadresultflag") {
              this.bChangeFlag = true;
          }
      },
      //----------------- class -----------------//
      //左侧主表 class
      lRowClassName({ row, rowIndex }) {
          if (this.AddData.indexOf(row.labgroupid) > -1) {
              return "row-new";
          }
          if (this.ModData.indexOf(row.labgroupid) > -1) {
              return "row-modify";
          }
      },
      //右侧子表 class
      rRowClassName({ row, rowIndex }) {
          if (this.$refs.rXTable.hasRowInsert(row)) {
              return "row-new";
          }
          if (this.$refs.rXTable.hasRowChange(row)) {
              return "row-modify";
          }
      },
      rCellClassName({ column, row }) {
          if (column.property == "labgroupid") {
              return "col-readonly";
          }
      },
  },
};
</script>

<style scoped>
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.top-title {
  margin: 0 3px 0 20px;
  font-size: 12px;
}
.top-button {
  right: 5px;
  position: absolute;
  top: 5px;
  display: flex;
  align-items: center;
}
.pagetop {
  width: 100%;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.detailxTable {
}
.detail-operation {
  display: flex;
  padding: 0px 2px 0px 5px;
  margin: 5px 0;
}
::v-deep .el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 2px 4px;
}
::v-deep .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}
::v-deep tr.vxe-body--row.row-modify {
  color: blue;
}
::v-deep tr.vxe-body--row.row-new {
  color: #cc6600;
}
::v-deep .col-readonly {
  background-color: #eeeeee;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
::v-deep .can-mod {
  background-color: rgb(255, 255, 255) !important;
}
::v-deep .vxe-table .vxe-cell {
  white-space: normal;
  word-break: break-word;
  padding: 0 5px;
}
::v-deep tr.vxe-body--row.row--current {
  color: #000000;
  font-weight: bold;
}
</style>
